package com.wzl.mixed.controller;

import com.wzl.common.VkPublicResponse;
import com.wzl.mixed.event.MpUserEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 观察者模式Spring之publishEvent事件处理
 *
 * @author weizhongli
 * @since 1.0, 2022/11/15 20:39
 */
@Slf4j
@Controller
@RequestMapping("/event")
public class MpPublishEventController {

    @Resource
    private ApplicationEventPublisher applicationEventPublisher;

    @RequestMapping("/test1")
    @ResponseBody
    public VkPublicResponse sengMessage1(String s){
        VkPublicResponse vkPublicResponse = new VkPublicResponse();
        log.info("我是事件1进来了啊");
        s = "啊哈哈哈哈哈";
        applicationEventPublisher.publishEvent(new MpUserEvent(s,"100"));
        return vkPublicResponse;
    }


    @RequestMapping("/test2")
    @ResponseBody
    public VkPublicResponse sengMessage2(String s){
        VkPublicResponse vkPublicResponse = new VkPublicResponse();
        log.info("我是事件2进来了啊");
        s = "啊哈哈哈哈哈";
        applicationEventPublisher.publishEvent(new MpUserEvent(s,"200"));
        return vkPublicResponse;
    }


}
